package game.combat;

import character.CharacterCombatControl;
import character.MyCharacter;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import game.DataStore;
import game.GameState;
import game.GameUtil;
import game.Main;
import game.StateSwitcher;

public class GuiAppState extends AbstractAppState implements ScreenController {
    TickingGuiControl guiControl = new TickingGuiControl();
    
    public void bind(Nifty nifty, Screen screen) {
        
    }

    public void onStartScreen() {
        
    }

    public void onEndScreen() {
        
    }
    
    @Override
    public void stateAttached(AppStateManager stateManager) {
        super.stateAttached(stateManager);
    }
    
    @Override
    public void stateDetached(AppStateManager stateManager) {
        super.stateDetached(stateManager);
    }
    
    @Override
    public void update(float tpf) {
	super.update(tpf);
        //this is just temp, for testing
        for(MyCharacter character : GameUtil.getAllCharactersInWorld()) {
            Main.floatingTexts.get(character.getId()).setText("HP: "+character.getCharacterStatus().getHitPoints());
            Main.floatingTexts.get(character.getId()).setLocalTranslation(DataStore.player.getCamera().getScreenCoordinates(character.getWorldTranslation().add(0, MyCharacter.HEIGHT, 0)).subtract(Main.floatingTexts.get(character.getId()).getLineWidth()/2, 0, 0));
        }
        if(DataStore.combatAppState.getCurrentCombatActor() instanceof MyCharacter) {
            MyCharacter currentCharacter = (MyCharacter)DataStore.combatAppState.getCurrentCombatActor();
            if(StateSwitcher.getGameState() == GameState.COMBAT && currentCharacter.getPlayer().equals(DataStore.player)) {
                int ticksRemainingForChar = currentCharacter.getCharacterStatus().getTicksPerTurn() - currentCharacter.getControl(CharacterCombatControl.class).getTicksUsed();
                Main.ticksText.setText("Ticks Remaining: " + ticksRemainingForChar);
            } else {
                Main.ticksText.setText(" ");
            }
        }
    }
}
